
class RunTests

  attr_accessor :tests

  once {
    @@runner = new
    Event.on('url:tests') { |e|
      e.respond :html => @@runner.run_tests(e)
    }
  }

  def run_tests e
    "<html><head>#{@@CSS}</head><body><pre>#{@@WE_LOVE_TDD}</pre>#{run_tests_output}</body></html>"
  end

  def run_tests_output
    test_cases.collect { |test|
      ::Test::Unit::UI::Html::TestRunner.run(test)
    }.join("\n")
  end

  def test_cases
    @tests || Testing::TestCase.all
  end


  @@WE_LOVE_TDD ||= <<LOVE
 __       __)                                    /
(, )  |  /        /)                    /)  /)  /
   | /| /   _    // ____ _   _    _/_ _(/ _(/  /
   |/ |/  _(/_  (/_(_) (/___(/_   (__(_(_(_(_ o
   /  |
LOVE

  @@CSS ||= <<CSS
<style>
body {
  font-family:consolas, 'cuourier new'
}
.result {
    padding:0.25em;
    margin-bottom:1px;
    color:white;
}
.result-red { background:red }
.faults {
      margin:0;
      margin-top:0.25em;
      padding:0.5em;
      background:white; color:black;
      font-family:consolas, 'cuourier new'
}
.result-green {
  background:green
}
</style>
CSS

end